<?php
/**
 * @Author: wangqi
 * @Email:   905766491@qq.com
 * @Date:   2017-02-10 18:28:37
 * @Last Modified by:   qi
 * @Last Modified time: 2017-02-22 15:59:52
 */
namespace frontend\modules\controllers;
use Yii;
use yii\web\controller;
use frontend\modules\models\Admin;

class PublicController extends Controller{
    public function actionLogin(){
        $this->layout=false;
        $model = new Admin;
        if(Yii::$app->request->isPost){
            $post = Yii::$app->request->post();
            $res = $model->login($post);
            if($res){
                $this->redirect(['default/index']);
                Yii::$app->end();
            }
        }
        return $this->render('login',['model'=>$model]);
    }

    public function actionLogout(){
        $cookie = Yii::$app->request->cookies->get('admin');
        //移除一个Cookie对象
        Yii::$app->response->getCookies()->remove($cookie);
        
        Yii::$app->session->removeAll();
        if(!isset(Yii::$app->session['admin']['isLogin'])){
            $this->redirect(['public/login']);
            Yii::$app->end();
        }
        $this->goback();
    }

    public function actionSeekpass(){
        $model = new Admin;
        $this->layout = false;
        if(Yii::$app->request->isPost){
            $post = Yii::$app->request->post();
            $res = $model->seekpass($post);
            if ($res) {
                Yii::$app->session->setFlash('info', '电子邮件已经发送成功，请查收');
            }
        }
        return $this->render('seekpass',['model'=>$model]);
    }
}